<?php

namespace Common\Validators;

use Phalcon\Validation\Validator,
    Phalcon\Validation\ValidatorInterface,
    Phalcon\Validation\Message;

class NumberValidator extends Validator implements ValidatorInterface
{

    /**
     * Executes the validation
     *
     * @param Phalcon\Validation $validator
     * @param string $attribute
     * @return boolean
     */
    public function validate($validator, $attribute)
    {
        $value = $validator->getValue($attribute);
        if (!is_numeric($value)) {
            $validator->appendMessage(new Message('The number is not valid', $attribute, 'Number'));
            return false;           
        }
        return true;
    }

}